package com.ruoyi.email;

import com.ruoyi.WarnNotification.service.IWarningNotificationService;
import com.ruoyi.user.service.IAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/kangyue")
public class sendEmailController {
    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private IWarningNotificationService warningNotificationService;
    @Autowired
    private IAppUserService IAppUserService;
    @GetMapping("/sendSimpleMessage")
    public void sendSimpleMessage(long UserId) {
        String userEmail = IAppUserService.getEmailByUserId(UserId);
        String notification = warningNotificationService.getUsernotifyContent(UserId);
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
            mailMessage.setFrom("2920957718@qq.com");
        //邮件主题
            mailMessage.setSubject("康悦健康平台异常通知");
        //邮件内容
            mailMessage.setText(notification);
        //收件人
            mailMessage.setTo(userEmail);
            javaMailSender.send(mailMessage);
            System.out.println("发送成功");
    }


}
